package edu.ahut.ssm;

import util.Evaluator;

import java.util.ArrayList;
import java.util.List;

public class DFSApp {
    static String[] s = "1 5 5 6 + - *".split("\\s+");
    static int n = 7;
    static int[] a = new int[n];
    static int[] book = new int[n];

    static void dfs(int k) {
        if (k >= n) {
            //System.out.println(Arrays.toString(a));
            List<String> exp = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                exp.add(s[a[i]]);
            }
            double ans = Evaluator.eval(exp);
            if (ans == 24.0)
                System.out.println(exp + ":" + Evaluator.eval(exp));
            return;
        }
        for (int i = 0; i < n; i++) {
            if (book[i] == 1) continue;
            a[k] = i;
            book[i] = 1;
            dfs(k + 1);
            book[i] = 0;
        }

    }

    public static void main(String[] args) {
        dfs(0);

    }
}
